home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / c_news / 13 / setattr.c < prev   
Text File  |  1988-11-07  |  2KB  |  77 lines

  1. /* setattr.c */
  2.  
  3.  
  4. /* Sets a file's archive bit either on or off */
  5. /* Compiled under Turbo C V. 1.5 */
  6.  
  7. #define ARCH_ON    0x20   /* set archive bit in attribute byte */
  8. #define ATTR_OFF    0x00   /* clear entire attribute byte */
  9. #define RD_ONLY    0x01     /* set read-only bit */
  10. #define SYSTM        0x04   /* set system file bit */
  11. #define HIDDN        0x02   /* set hidden file bit */
  12.  
  13. #define GET            0      /* used with _chmod to read a file's
  14.                                     attribute byte */
  15. #define SET           1      /* used with _chmod to set a file's
  16.                                      attribute byte */
  17.  
  18. #include "stdio.h"
  19. #include "io.h"
  20.  
  21.  
  22.  
  23. main (argc, argv)
  24. int argc;
  25. char *argv[];
  26. {
  27. if (argc != 3) {
  28.     printf("Format: SETATTR ON <filename> or SETATTR OFF <filename>\n");
  29.                     }
  30.  
  31. /* set the file's archive bit */
  32.  
  33. if (strcmp(argv[1], "ON") == 0 || strcmp(argv[1], "on") == 0) {
  34.     _chmod(argv[2], SET, ARCH_ON);
  35.     printf("\nArchive Bit for %s has been set ON.\n", argv[2]);
  36.                                                                                  }
  37. /* clear the file's archive bit (as well as it's read-only bit, etc.) */
  38.  
  39. if (strcmp(argv[1], "OFF") == 0 || strcmp(argv[1], "off") == 0) {
  40.     _chmod(argv[2], SET, ATTR_OFF);
  41.     printf("\nArchive Bit for %s has been set OFF.\n", argv[2]); }
  42.  
  43. }
  44.  
  45. /* This little program uses the _chmod function defined in io.h
  46.     to set or release a file's archive bit.  The _chmod function
  47.     can also be used to set other file attributes, such as read-only,
  48.     hidden, system file, etc. (see #define's above).  More than one
  49.     attribute can be set at a time by ORing the masks together.  For
  50.     example, to set a file's archive and read-only bits on you could
  51.     use: _chmod("filename", SET, 0x20|0x01).  If _chmod's second
  52.     argument is set to 0 (or GET using the #define above), it will
  53.     return the current file attribute instead of setting it:
  54.  
  55.     int attrib;
  56.  
  57.     attrib = _chmod("filename", GET, 0x20);
  58.  
  59.     When using _chmod to read a file's attribute byte, you must
  60.     include the third argument but it really does not do anything.
  61.     The file's attributes can be represented in decimal as follows:
  62.  
  63.     Bit          Value              Meaning
  64.  
  65.     0                    1                        Read-only file
  66.     1                    2                        Hidden File
  67.     2                    4                        System File
  68.     3                    8                        Volume Label Name
  69.     4                  16                        Subdirectory Name
  70.     5                  32                        Archive
  71.     6                  64                        Unused
  72.     7                128                        Unused
  73.  
  74.     The preceding table was taken from Turbo C - The Complete
  75.     Reference by Herbert Schildt, Page 236.
  76.  
  77. */